package cn.kxlove.controller;

import cn.kclove.service.ItemService;
import cn.kxlove.common.EUDataGridResult;
import cn.kxlove.pojo.TbItem;
import cn.kxlove.util.TaotaoResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 郑开心
 * @date 16/1/26
 */
@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;

    @RequestMapping("/item/{itemId}")
    @ResponseBody
    public TbItem getItemById(@PathVariable Long itemId) {
        TbItem tbItem = itemService.getItemById(itemId);
        return tbItem;
    }

    @RequestMapping("/item/list")
    @ResponseBody
    public EUDataGridResult getItemList(Integer page, Integer rows) {
        EUDataGridResult result = itemService.getItemList(page, rows);
        return result;
    }

    @RequestMapping(value="/item/save", method= RequestMethod.POST)
    @ResponseBody
    private TaotaoResult createItem(TbItem item,String desc,String itemParams) throws Exception {
        return itemService.createItem(item,desc,itemParams);
    }

    @RequestMapping("/item/edit")
    private String editItem(){

        return "item-edit";
    }

    @RequestMapping("/item/query/item/desc/{itemId}")
    @ResponseBody
    private TaotaoResult queryItemDesc(@PathVariable long itemId){
        return itemService.queryItemDesc(itemId);
    }
    @RequestMapping(value = "/item/update", method = RequestMethod.POST)
    @ResponseBody
    private TaotaoResult updateItem(TbItem item,String desc) throws Exception {
        return itemService.updateItem(item,desc);
    }

}
